package com.atguigu.controller;


import com.alibaba.dubbo.config.annotation.Reference;
import com.atguigu.constant.MessageConstant;
import com.atguigu.entity.Result;
import com.atguigu.pojo.Address;
import com.atguigu.service.AddressService;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/Address")
public class AddressController {
    @Reference
    private AddressService addressService;


    @RequestMapping("/findAllMaps")
    public Map findAllMaps(){
        try {
            //查出来所有的地址
            List<Address>list =addressService.findAll();

            List<Map<String,String>> gridnMaps = new ArrayList<Map<String,String>>();
            List<Map<String,String>> nameMaps=new ArrayList<Map<String,String>>();

            for (Address address : list) {
                Map<String,String> gridn =new HashMap<String, String>();
                gridn.put("lng",address.getLng());
                gridn.put("lat",address.getLat());
                gridnMaps.add(gridn);

                Map<String,String> nameMap =new HashMap<String, String>();
                nameMap.put("addressName",address.getAddressName());
                nameMaps.add(nameMap);
            }


            Map map =new HashMap();
            map.put("gridnMaps",gridnMaps);
            map.put("nameMaps",nameMaps);

            return map;
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }
}
